package com.zygh.policeasset.controller;

import com.alibaba.fastjson.JSONObject;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.TaskSource;
import com.zygh.policeasset.service.TaskSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/task-source"})
@Api(tags = {"任务来源管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/TaskSourceController.class */
public class TaskSourceController {
    @Autowired
    TaskSourceService taskSourceService;

    @GetMapping({"/queryAll"})
    @ApiOperation("查询所有任务来源")
    public Object queryAll() {
        return this.taskSourceService.queryAll();
    }

    @PutMapping({"/update"})
    @ApiOperation("修改")
    public Object update(@RequestBody TaskSource taskSource) {
        if (this.taskSourceService.update(taskSource).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @PostMapping({"/add"})
    @ApiOperation("添加")
    public Object add(@RequestBody JSONObject json) {
        if (this.taskSourceService.add(json.getString("name")).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @DeleteMapping({"/delete/{id}"})
    @ApiOperation("删除")
    public Object delete(@PathVariable Integer id) {
        if (this.taskSourceService.delete(id).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }
}